<template>
  <view class="container">
    <z-paging
      ref="paging"
      v-model="itemList"
      @query="queryList"
      :fixed="true"
      :auto="false"
      :auto-show-back-to-top="true"
      :empty-view-img="`${getImageUrl('empty.png')} `"
      empty-view-text="暂无数据~"
      :empty-view-img-style="imgStyle"
    >
      <view slot="top">
        <u-navbar
          backIconColor="#333333"
          title-size="36"
          title="联盟豆"
          height="50"
          :is-back="true"
          :border-bottom="false"
          title-color="#333333"
        >
        </u-navbar>
        <u-gap height="20"></u-gap>
        <view class="card" v-if="setting">
          <view class="cell">
            <view class="dis-flex flex-y-center flex-y-between">
              <view class="label">剩余联盟豆</view>
              <view class="cell-right dis-flex flex-y-center" @click="showRuleModel = true">
                <text style="margin-right: 10rpx">规则说明</text>
                <u-icon name="/static/tishi-b.png" size="28"></u-icon>
              </view>
            </view>
            <view class="value dis-flex flex-y-center flex-y-between">
              <view>{{ setting.cryptocurrencyOrigin }}</view>
              <view class="flex-1"></view>
              <view class="bt" @click="routeTo('/alliance/invest')">兑换投入</view>
              <view class="bt warning" @click="routeTo('/alliance/exchange?type=1')"
                >兑换收益豆</view
              >
            </view>
          </view>
        </view>
        <u-gap height="20"></u-gap>
      </view>
      <view class="card" style="padding-top: 0">
        <view class="headView">
          <view class="top dis-flex flex-y-between flex-y-center">
            <view class="dis-flex" @click="showPiker = true">
              <text>{{ year }}年{{ month }}月</text>
              <u-icon
                style="margin-left: 4rpx"
                name="arrow-down"
                color="#333333"
                size="30"
              ></u-icon>
            </view>
            <view class="" @click="showBizTypes = true">
              <text>全部</text>
              <u-icon
                style="margin-left: 6rpx"
                name="arrow-down"
                color="#333333"
                size="30"
              ></u-icon>
            </view>
          </view>
          <view class="bottom" v-if="extra">
            <text>收入：{{ extra.inNumberSum }} </text>
            <text style="margin-left: 10rpx">支出：{{ extra.outNumberSum }}</text>
          </view>
          <u-line v-if="itemList.length > 0"></u-line>
        </view>

        <view class="list-box" v-for="(item, index) in itemList" :key="index">
          <view class="top dis-flex flex-y-between">
            <view class="cate">{{ item.mark }}</view>
            <view class="num" v-if="item.number < 0">{{ item.number }}</view>
            <view class="num add" v-else>+{{ item.number }}</view>
          </view>
          <view class="bottom dis-flex flex-y-between">
            <view class="date">{{ $u.timeFormat(item.createTime, 'yyyy-mm-dd hh:MM') }}</view>
            <view class="y">剩余{{ item.balance }}</view>
          </view>
        </view>
      </view>
    </z-paging>
    <u-popup v-model="showRuleModel" mode="center" width="600" height="auto" border-radius="20">
      <view class="rule_box">
        <view class="tl"> 规则说明 </view>
        <u-parse
          v-if="setting"
          class="content"
          :html="setting.cryptocurrencyIncrementTips"
        ></u-parse>
        <view class="bt" @click="showRuleModel = false">知道了</view>
      </view>
    </u-popup>
    <u-picker v-model="showPiker" :params="params" @confirm="comfirmDate"></u-picker>
    <u-picker
      v-if="setting"
      v-model="showBizTypes"
      mode="selector"
      :range="setting.bizTypes"
      range-key="name"
      @confirm="comfirmType"
    ></u-picker>
  </view>
</template>

<script>
export default {
  data() {
    return {
      showRuleModel: false,
      showPiker: false,
      showBizTypes: false,
      imgStyle: {
        width: '12rem'
      },
      itemList: [],
      setting: null,
      extra: null,
      year: '',
      month: '',
      params: {
        year: true,
        month: true,
        day: false
      },
      biztype: ''
    }
  },
  onLoad() {
    this.$u.get('/app-api/member/digital-assets/cryptocurrency/overview').then((res) => {
      this.setting = res.data
    })
  },
  onShow() {
    let today = new Date()
    this.year = today.getFullYear()
    this.month = today.getMonth() + 1 < 10 ? '0' + (today.getMonth() + 1) : today.getMonth() + 1
    this.queryList()
  },
  methods: {
    // toDetail() {
    // 	this.$utils.route('/alliance/order-detail')
    // },
    routeTo(url) {
      uni.navigateTo({
        url: url
      })
    },
    queryList(page = 1, pageSize = 10) {
      this.$u
        .get('/app-api/pay/bill/page', {
          pageNo: page,
          pageSize,
          category: 'cryptocurrency_origin',
          type: this.biztype,
          year: this.year,
          month: this.month
        })
        .then((res) => {
          // let dynamicPaging = this.scurrent > 0 ? 'paging' + this.scurrent : "paging"
          this.$refs.paging.complete(res.data.list)
          this.extra = res.data.extra
        })
    },
    comfirmDate(res) {
      this.year = res.year
      this.month = res.month
      this.queryList()
    },
    comfirmType(res) {
      this.biztype = this.setting.bizTypes[res[0]].code
      this.queryList()
    }
  }
}
</script>

<style scoped lang="scss">
// page {
// 	height: 100%;
// }

// .container {
// 	height: 100vh;
// }

.card {
  background: #ffffff;
  border-radius: 10rpx;
  margin: 0 20rpx;
  padding: 30rpx 20rpx;
}
.rule_box {
  padding: 45rpx 30rpx 35rpx 30rpx;
  .tl {
    font-weight: 600;
    font-size: 34rpx;
    margin-bottom: 45rpx;
    text-align: center;
  }
  .content {
    font-size: 30rpx;
    line-height: 45rpx;
  }
  .bt {
    width: 240rpx;
    height: 72rpx;
    background: #10a28f;
    border-radius: 36rpx;
    margin: auto;
    font-size: 30rpx;
    color: #ffffff;
    line-height: 72rpx;
    margin-top: 35rpx;
    text-align: center;
  }
}

.cell {
  margin-bottom: 20rpx;

  .label {
    font-size: 24rpx;
    color: #333333;
    margin-right: 20rpx;
  }

  .value {
    font-weight: 600;
    font-size: 48rpx;
    color: #333333;
    margin-top: 20rpx;
    .bt {
      width: 136rpx;
      height: 50rpx;
      background: #10a28f;
      border-radius: 25rpx;
      font-size: 24rpx;
      color: #ffffff;
      line-height: 50rpx;
      text-align: center;
    }
    .warning {
      background: #ff6f10;
      margin-left: 20rpx;
    }
  }

  .cell-right {
    font-size: 24rpx;
    color: #999999;
  }
}

.cell:last-child {
  margin-bottom: 0;
}

.list-box {
  padding: 25rpx 0 30rpx 0;
  border-bottom: 1rpx solid #f5f5f5;

  .top {
    font-size: 28rpx;
    margin-bottom: 20rpx;

    .num {
      font-weight: 600;
      font-size: 30rpx;
      color: #333333;
      margin-left: 78rpx;
    }

    .add {
      color: #10a28f;
    }
  }

  .bottom {
    font-size: 24rpx;
    color: #999999;
  }
}

.list-box:last-child {
  border: none;
}

.headView {
  position: sticky;
  background: #fff;
  z-index: 100;
  height: 138rpx;
  top: 0px;
  padding-top: 25rpx;

  .top {
    font-size: 30rpx;
    margin-bottom: 20rpx;
  }

  .bottom {
    font-size: 26rpx;
    color: #999999;
    margin-bottom: 25rpx;
  }
}
</style>
